/**
 * 
 */
package negocio.Color;

import integracion.Factoria.*;
import integracion.Color.DAOColor;
import integracion.Vehiculo.DAOVehiculo;

public class SAColorImp implements SAColor {
	

	@Override
	public boolean crearColor(TransferColor t) {	

		 FactoriaDAO FacTdao = FactoriaDAO.getInstancia();
		 DAOColor daoColor = FacTdao.newDAOColor();
		 if(daoColor.creable(t))
			 return daoColor.create(t);
		 return false;
	}

	@Override
	public boolean eliminarColor(TransferColor t) {
		
		FactoriaDAO FactDao = FactoriaDAO.getInstancia();
		DAOColor daoColor = FactDao.newDAOColor();			
		DAOVehiculo daoVehiculo = FactDao.newDAOVehiculo();	
	
		if(daoColor.deletable(t) && !daoVehiculo.containsColor(t.getId()))
			return daoColor.delete(t);
		return false;
	}

	@Override
	public TransferColor buscarColor(int id) {
		
		FactoriaDAO FactDao = FactoriaDAO.getInstancia();
		DAOColor daoColor = FactDao.newDAOColor();
		if(daoColor.searchable(id))
			return daoColor.readById(id);
		return null;
	}

	@Override
	public boolean actualizarColor(TransferColor t) { 		
		FactoriaDAO FactDao = FactoriaDAO.getInstancia();
		DAOColor daoColor = FactDao.newDAOColor();
		if(daoColor.updatable(t))
			return daoColor.update(t);
		return false;
	}
	
	
	
}